<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-08-15
 * Time: 15:09
 */
//检测用户有没有登录
namespace app\admin\behavior;
class ListenLoginStatus {


    public function run($params){


//        echo '0000;
        $loginSession = session('WST_STAFF');
        $allowUrl = [   'admin/index/login',
                        'admin/index/checklogin',
                        'admin/index/logout',
                        'admin/index/logout',
                        'admin/index/getverify',
                        'admin/cronjobs/autocancelnopay',
                        'admin/cronjobs/autoappraise',
                        'admin/cronjobs/autoreceive',
                        'admin/cronjobs/autofilexml',
                        'admin/orderrefunds/wxrefundnodify',
                        'admin/orderrefunds/wxapprefundnodify'
        ];

        $request = request();
        //字符转换为小写：
        $visit = strtolower($request->module().'/'.$request->controller().'/'.$request->action());

        if(empty($loginSession)&&!in_array($visit,$allowUrl)){

            if($request->isAjax()){
                echo $request->isAjax();
                echo json_encode(['status'=>-999,'msg'=>'对不起，您还没有登录，请先登录']);
            }else{
                header("Location:".url('admin/index/login'));
            }
//            exit();


        }



    }
}